#include "mainwindow.h"
#include "appsettings.h"
#include "widgets/logdock.h"

#include <QtCore/qdatetime.h>
#include <QtCore/qdebug.h>
#include <QtCore/qfile.h>
#include <QtCore/qmutex.h>
#include <QtCore/qtextcodec.h>
#include <QtCore/qtextstream.h>
#include <QtCore/qtranslator.h>
#include <QtGui/qapplication.h>

void myMessageOutput(QtMsgType type, const char *msg)
{
    LogDock::addMessage(QString::fromUtf8(msg), type);
}

int main(int argc, char *argv[])
{
    QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
    QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
    QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
    Q_INIT_RESOURCE(doker);

    qInstallMsgHandler(myMessageOutput);

    QApplication a(argc, argv);

    QTranslator translator;
    QString suffix = g_appSettings->asString("View/Language", "en");
    if (suffix != "en")
    {
        translator.load("doker_" + suffix, ":/translations");
        a.installTranslator(&translator);
    }

    MainWindow w;
    w.show();
    
    return a.exec();
}
